(function ($){
	// tab插件调用
	$.fn.hoverElement=function(options){
		var defaults={
			
			tabCls:'tab',
			tabitam:'tab_tieam',
			tabselt:'cur'


		};
		var tab=$(this);
		var options=$.extend(defaults,options);	
		 //选项卡 this指通过当前选择器获取的JQuery对象
		var tab=$('.tab_menu ul li',this);
		 //选项内容		
		var tabContent = $(".brand_up > div", this);
		
		

		$(this).find('ul li').click(function(){
			
			$(this).addClass(options.tabselt).siblings().removeClass(options.tabselt)
			var curIndex=tab.index(this);
			tabContent.eq(curIndex).show().siblings().hide();
			

		});

		return this;

	};


	// 轮播插件调用
	$.fn.ScrollPic = function (option) {
        return this.each(function () {
            var defaults = {
                ele: '.yiz-slider-1',
                Time: '2000',
                speed: '1000',
                autoscrooll: true,
                arrowcontrol: false,
                numbercontrol: true
            };

            var opts = $.extend({}, defaults, option);
            var PicObject = $(this);
            var scrollList = PicObject.find('ul');
            var listLi = scrollList.find('li');


            var index = 0;
            var picTimer;
            var pWidth = PicObject.width()
            var pHeight = PicObject.height()
            var len = PicObject.find("li").length;
            var sWidth = scrollList.find('li').width();
			var listImg=listLi.find('img');
            listLi.css({ "width": pWidth, "height": pHeight })
			listImg.each(function(i,item){
				var self=this;
				var rePosotion=function(){
					var width=$(self).width(),
						releft;
					if(width>pWidth){
						releft=(width-pWidth)/2;
					}else{
						releft=0;
					}
					$(self).css({ "width": width, "height": pHeight ,left:-releft,position:'relative'})
				}
				rePosotion();
				item.onload=function(){
					rePosotion();
				}
			})
            
            scrollList.css("width", pWidth * len)

            
            function picTimer() {
                index++;
                if (index == len) { index = 0; }
                showPics(index);
            }//自动切换函数
            if (opts.autoscrooll) { var time = setInterval(picTimer, opts.Time) } else { $(".yiz-page-btn").hide() }

                function showPics(index) {
                    var nowLeft = -index * pWidth;
                    PicObject.find(scrollList).stop(true, false).animate({ "left": nowLeft }, opts.speed);
                    PicObject.find(paging).eq(index).addClass('current').siblings().removeClass('current');
            }//动画函数

            if (opts.numbercontrol) {
                PicObject.append('<div class="yiz-page-btn"></div>')
                for (i = 1; i <= len; i++) {
                    PicObject.find('.yiz-page-btn').append('<span>' + i + '</span>')
                }
                var paging = PicObject.find(".yiz-page-btn span");
                paging.eq(index).addClass('current')
                PicObject.find(paging).on('touchstart mouseover',function (e) {
                   e.preventDefault()
                   index = PicObject.find(paging).index($(this));
                   showPics(index)
                });//鼠标经过1、2、3、4的效果
            }

            if (opts.arrowcontrol) {
                PicObject.append('<span class="yiz-leftarrow"></span><span class="yiz-rightarrow"></span>')
                var prev = PicObject.find('span.yiz-leftarrow');
                var next = PicObject.find('span.yiz-rightarrow');
                prev.on('click',function (e){
                    e.preventDefault()
                    index -= 1;
                    if (index == -1) { index = len - 1; }
                    showPics(index);
                });//上一页

                next.on('click',function (e){
                    e.preventDefault()
                    index += 1;
                    if (index == len) { index = 0; }
                    showPics(index);
                });//下一页

                
            }
            PicObject.on('touchstart mouseover',function (e) {
                clearInterval(time);
            })
            PicObject.on('mouseleave',function (e) {
                if (opts.autoscrooll) { time = setInterval(picTimer, opts.Time); } else { clearInterval(time); PicObject.find('$(".yiz-page-btn")').hide() }
            });//清除计时器

           //phone
           

            //支持手势事件
            function isTouchDevice() {  
                try {  //phone
                    document.createEvent("TouchEvent"); 
                    var startX = 0,endX = 0;   
                    PicObject.on('touchstart',function(e){
                      e.preventDefault()
                      var touch = event.touches[0];
                               startX = touch.pageX;
                  })
                    PicObject.on('touchmove',function(e){
                       var touch2 = event.touches[0];
                               endX = touch2.pageX;
                        if(startX==endX){
                            return
                        }
                       if(!scrollList.is(":animated")){ 
                          e.preventDefault()

                         
                        if(startX>endX+100){
                          index += 1;
                          if (index == len) { index = 0; }
                          showPics(index);
                          (startX=endX+100)
                      }
                      if(startX<endX-100){
                         index -= 1;
                         if (index == -1) { index = len - 1; }
                         showPics(index);
                         (startX=endX-100)
                     }
                 }
             })
                    PicObject.on('touchend',function(e){
                        time = setInterval(picTimer, opts.Time)
                    })


                    
                }  
                catch (e) {  //pc

                }  
            }  
            isTouchDevice()

    })
  }

   // 左右轮播滚动

  $.fn.jCarouselLite = function(o) {
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 200,
        easing: null,

        vertical: false,
        circular: true,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
            ul.prepend(tLi.slice(tl-v-1+1).clone())
              .append(tLi.slice(0,v).clone());
            o.start += v;
        }

        var li = $("li", ul), itemLength = li.size(), curr = o.start;
        div.css("visibility", "visible");

        li.css({overflow: "hidden", float: o.vertical ? "none" : "left"});
        ul.css({margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1"});
        div.css({overflow: "hidden", position: "relative", "z-index": "2", left: "0px"});

        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css({width: li.width(), height: li.height()});
        ul.css(sizeCss, ulSize+"px").css(animCss, -(curr*liSize));

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images

        if(o.btnPrev)
            $(o.btnPrev).click(function() {
                return go(curr-o.scroll);
            });

        if(o.btnNext)
            $(o.btnNext).click(function() {
                return go(curr+o.scroll);
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) {
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() {
                go(curr+o.scroll);
            }, o.auto+o.speed);

        function vis() {
            return li.slice(curr).slice(0,v);
        };

        function go(to) {
            if(!running) {

                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;

                ul.animate(
                    animCss == "left" ? { left: -(curr*liSize) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev)
                        ||
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
  };
  function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
  };
  function width(el) {
      return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
  };
  function height(el) {
      return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
  };


	

})(jQuery);